package com.minimalist.common.entity.basic.po;

import com.mybatisflex.annotation.Table;
import com.minimalist.common.config.mybatis.InsertFullColumnHandler;
import com.minimalist.common.config.mybatis.UpdateFullColumnHandler;
import com.minimalist.common.config.mybatis.bo.BaseEntity;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 租户表 实体类。
 *
 * @author 小太阳
 * @since 2024-10-18
 */
@Table(value = "m_tenant", onInsert = InsertFullColumnHandler.class, onUpdate = UpdateFullColumnHandler.class)
public class MTenant extends BaseEntity implements Serializable{

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 租户ID
     */
    private Long tenantId;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 租户套餐ID
     */
    private Long packageId;

    /**
     * 租户名
     */
    private String tenantName;

    /**
     * 租户过期时间
     */
    private LocalDateTime expireTime;

    /**
     * 可创建账号数量
     */
    private Integer accountCount;

    /**
     * 数据隔离方式  column字段隔离(默认)  db数据库隔离
     */
    private String dataIsolation;

    /**
     * 数据源名称  master默认使用主库
     */
    private String datasource;

    /**
     * 存储ID 表示该租户使用哪个文件存储
     */
    private Long storageId;

    /**
     * 状态 0禁用 1正常
     */
    private Integer status;

    /**
     * 备注
     */
    private String remark;

    // 无参构造函数
    public MTenant() {
    }

    // 全参构造函数
    public MTenant(Long tenantId, Long userId, Long packageId, String tenantName, LocalDateTime expireTime, 
                   Integer accountCount, String dataIsolation, String datasource, Long storageId, 
                   Integer status, String remark) {
        this.tenantId = tenantId;
        this.userId = userId;
        this.packageId = packageId;
        this.tenantName = tenantName;
        this.expireTime = expireTime;
        this.accountCount = accountCount;
        this.dataIsolation = dataIsolation;
        this.datasource = datasource;
        this.storageId = storageId;
        this.status = status;
        this.remark = remark;
    }

    // Getter和Setter方法
    public Long getTenantId() {
        return tenantId;
    }

    public void setTenantId(Long tenantId) {
        this.tenantId = tenantId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Long getPackageId() {
        return packageId;
    }

    public void setPackageId(Long packageId) {
        this.packageId = packageId;
    }

    public String getTenantName() {
        return tenantName;
    }

    public void setTenantName(String tenantName) {
        this.tenantName = tenantName;
    }

    public LocalDateTime getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(LocalDateTime expireTime) {
        this.expireTime = expireTime;
    }

    public Integer getAccountCount() {
        return accountCount;
    }

    public void setAccountCount(Integer accountCount) {
        this.accountCount = accountCount;
    }

    public String getDataIsolation() {
        return dataIsolation;
    }

    public void setDataIsolation(String dataIsolation) {
        this.dataIsolation = dataIsolation;
    }

    public String getDatasource() {
        return datasource;
    }

    public void setDatasource(String datasource) {
        this.datasource = datasource;
    }

    public Long getStorageId() {
        return storageId;
    }

    public void setStorageId(Long storageId) {
        this.storageId = storageId;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    // equals和hashCode方法
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        MTenant mTenant = (MTenant) o;
        return Objects.equals(tenantId, mTenant.tenantId) &&
               Objects.equals(userId, mTenant.userId) &&
               Objects.equals(packageId, mTenant.packageId) &&
               Objects.equals(tenantName, mTenant.tenantName) &&
               Objects.equals(expireTime, mTenant.expireTime) &&
               Objects.equals(accountCount, mTenant.accountCount) &&
               Objects.equals(dataIsolation, mTenant.dataIsolation) &&
               Objects.equals(datasource, mTenant.datasource) &&
               Objects.equals(storageId, mTenant.storageId) &&
               Objects.equals(status, mTenant.status) &&
               Objects.equals(remark, mTenant.remark);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), tenantId, userId, packageId, tenantName, expireTime, 
                           accountCount, dataIsolation, datasource, storageId, status, remark);
    }

    // Builder模式
    public static MTenantBuilder builder() {
        return new MTenantBuilder();
    }

    public static class MTenantBuilder {
        private Long tenantId;
        private Long userId;
        private Long packageId;
        private String tenantName;
        private LocalDateTime expireTime;
        private Integer accountCount;
        private String dataIsolation;
        private String datasource;
        private Long storageId;
        private Integer status;
        private String remark;

        public MTenantBuilder tenantId(Long tenantId) {
            this.tenantId = tenantId;
            return this;
        }

        public MTenantBuilder userId(Long userId) {
            this.userId = userId;
            return this;
        }

        public MTenantBuilder packageId(Long packageId) {
            this.packageId = packageId;
            return this;
        }

        public MTenantBuilder tenantName(String tenantName) {
            this.tenantName = tenantName;
            return this;
        }

        public MTenantBuilder expireTime(LocalDateTime expireTime) {
            this.expireTime = expireTime;
            return this;
        }

        public MTenantBuilder accountCount(Integer accountCount) {
            this.accountCount = accountCount;
            return this;
        }

        public MTenantBuilder dataIsolation(String dataIsolation) {
            this.dataIsolation = dataIsolation;
            return this;
        }

        public MTenantBuilder datasource(String datasource) {
            this.datasource = datasource;
            return this;
        }

        public MTenantBuilder storageId(Long storageId) {
            this.storageId = storageId;
            return this;
        }

        public MTenantBuilder status(Integer status) {
            this.status = status;
            return this;
        }

        public MTenantBuilder remark(String remark) {
            this.remark = remark;
            return this;
        }

        public MTenant build() {
            return new MTenant(tenantId, userId, packageId, tenantName, expireTime, accountCount, 
                              dataIsolation, datasource, storageId, status, remark);
        }
    }

}
